#ifndef Window_First
#define Window_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Clipper.h"
#include "WindowSystem.h"

class Manager;
class WindowPort;
class Menu;

extern Token
	gToken,
	gLastClickToken;
extern Window *gWindow;

//---- Window ------------------------------------------------------------------

class Window: public Clipper {
public:
	MetaDef(Window);

	Window(Manager*, const Point &e, WindowFlags f, VObject*,
				const char *title= "");
	Window(Manager*, VObject *contents, WindowType wt, WindowFlags f,
				const Point &e= gPoint_1, const char *t= "");
	~Window();

	//---- queries
	bool IsActive();
	EvtHandler *GetNextHandler();
	void SetNextManager(Manager*);
	Port *GetPortDesc();
	void SetPortDesc(Port *newport);
	Rectangle ScreenRect();
	Rectangle GetRect();
	GrCursor GetCursor(Point);

	//---- callbacks
	void InputNotify(Token *t);
	void FocusNotify(bool f);
	void OpenNotify(const Point &e);
	void CloseNotify();
	void ResizeNotify(const Point &e);

	//---- window management, layout
	void SetOrigin(Point at);
	void SetExtent(Point e);
	void ExtentChanged(VObject *what);
	void Top();
	void Bottom();
	Window *MakeIcon();
	Window *GetIcon();
	void Open(bool mode= TRUE);
	void OpenAt(const Point &p, VObject *vf= 0, bool resize= FALSE,
							bool block= FALSE);
	void Iconize();
	void SetTitle(const char *t);
	int GetId();
	
	//---- drawing
	void Focus();
	void InvalidateRect(Rectangle);

	//---- events
	void ReadEvent(Token &t);
	void Fullscreen(bool on);

	//---- misc
	void InspectorId(char *buf, int sz);
	void Bell(long d= 100);
	void SetMousePos(const Point &p);

	//---- drag & drop
	int DragDropNotify(int code, const Point &p, Rectangle *rp);
	static int DragDrop(int code, const Point &p, Window *w);

protected:
	void Init(Manager *eh, VObject *in, WindowType wt, GrCursor curs,
				WindowFlags f, const char *t, const Point &e);
	WindowPort *MakePort();

protected:
	bool active;
	GrCursor cursor;
	WindowPort *portDesc;     // Port descriptor
	Manager *manager;
	Window *icon;
	VObject *inner;
	WindowType wtype;
	WindowFlags wflags;
};

inline bool Window::IsActive()
	{ return active; }
inline Window *Window::GetIcon()
	{ return icon; }
inline Port *Window::GetPortDesc()
	{ return (Port*)portDesc; }

#endif

